import request from "@/utils/request";

export function HTTP(options) {
  let { url, data, method, postfile, responseType } = options;

  if (!method) {
    method = "POST";
  }
  let req = {
    url,
    method,
    headers: {
      Accept: "application/json",
      "Content-Type": "application/json;charset=UTF-8",
    },
    responseType: responseType ? responseType : "json",
  };
  // let _data = postfile ? paramsToFormData(encryption(data, true)) : encryption(data)
  let _data = data;
  if (method.toUpperCase() === "POST" || method.toUpperCase() === "PUT") {
    if (postfile) {
      req.headers = { "Content-Type": "multipart/form-data" };
      req.data = _data;
    } else {
      req.data = JSON.stringify(_data);
    }
  } else {
    req.params = data;
  }
  return request(req);
}
